"""状态模式"""
from abc import ABCMeta, abstractmethod


class Water:
    """"""

    def __init__(self):
        self.__temperature = 25
        self.__state = LiquidState()

    def get_temperature(self):
        return self.__temperature

    def set_temperature(self, temperature):
        self.__temperature = temperature

        if self.__temperature <= 0:
            self.__state = SolidState()
        elif self.__temperature >= 100:
            self.__state = GaseousState()
        else:
            self.__state = LiquidState()

    def behavior(self):
        self.__state.behavior(self)


class State(metaclass=ABCMeta):
    name = ""

    def behavior(self, water):
        """行为"""
        print(f"状态：{self.name} 温度：{water.get_temperature()}")


class SolidState(State):
    """固态"""
    name = "固态"


class LiquidState(State):
    """液态"""
    name = "液态"


class GaseousState(State):
    """气态"""
    name = "气态"


if __name__ == '__main__':
    water = Water()
    water.behavior()

    water.set_temperature(-1)
    water.behavior()

    water.set_temperature(101)
    water.behavior()
